//
//  YCPresentationController.m

#import "RBPresentationController.h"
#import "RBCommonCenterAlterController.h"
@interface RBPresentationController()
@end
@implementation RBPresentationController

- (void)containerViewWillLayoutSubviews{
    [super containerViewWillLayoutSubviews];
    
    // 设置弹出视图尺寸
    if (_popoverType == RBPopoverTypeAlert) {
        self.presentedView.frame = CGRectMake(self.containerView.center.x - self.presentedSize.width * 0.5, self.containerView.center.y - self.presentedSize.height * 0.5, self.presentedSize.width, self.presentedSize.height);
    }else{
        self.presentedView.frame = CGRectMake(0, self.containerView.bounds.size.height - self.presentedHeight, self.containerView.bounds.size.width, self.presentedHeight);
    }
    //添加蒙版
    [self.containerView insertSubview:self.coverView atIndex:0];
}

- (UIView *)coverView{
    if (!_coverView) {
        _coverView = [[UIView alloc] initWithFrame:self.containerView.bounds];
        _coverView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:self.coverViewAlpha];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(coverViewClick)];
        [_coverView addGestureRecognizer:tap];
    }
    return _coverView;
}

- (void)coverViewClick{
   
    if ([self.presentedViewController isKindOfClass:[RBCommonCenterAlterController class]]) { // 如果是隐私弹框这个类，就需要点击关闭空白处，手势禁止
        return;
    }
    [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}
@end
